package com.youmu.sichuansfc.util;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 *  拉取企业信息
 */
public class CompanyDetailUtil {

    private final  static String host = "http://cdetail.market.alicloudapi.com";
    private final  static String path = "/lianzhuo/cdetails";
    private final  static String appcode = "60614266408c40fc8d286f7a4fd0eab0";

    /**
     *  拉取企业信息
     *      企业名字 == 查询
     * @param name 企业名字
     * @return
     */
    public static String getCompanyDetail(String name){
        if (name.isEmpty()){
            return null;
        }

        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();

        try {
            JSONObject rst = HttpRequestUtil.sendGet(host+path+"?keyword="+name,headers);
            return rst.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }


    public static void main(String[] args) {

        //AppSecret:58927fb076f4cdffa6ebee71bef8a50c
       // AppKey:23475655
       // AppCode:60614266408c40fc8d286f7a4fd0eab0

        String host = "http://cdetail.market.alicloudapi.com";
        String path = "/lianzhuo/cdetails";
        String method = "GET";
        String appcode = "60614266408c40fc8d286f7a4fd0eab0";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("keyword", "遂宁市中通实业集团有限公司");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
           // HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            JSONObject rst = HttpRequestUtil.sendGet(host+path+"?keyword="+"遂宁市中通实业集团有限公司",headers);
            //System.out.println(response.toString());
            //获取response的body
//            if(("200").equals(rst.resp.RespCode)){
//
//            }
            System.out.println(rst);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

